DataHandler.JSONDataHandler

Types

PariahJSON

Represents a JSON file on disk along with its parsed data.

  • Fields:

    • string FileName (read-only): The name of the JSON file (without extension).
    • string FilePath (internal set): The directory path where the file resides.
    • JObject Data (read-only): The parsed JSON content.
  • Constructor:
    csharp
    PariahJSON(string fileName, string filePath, JObject data)

Initializes a new instance with the given file name, file path, and JSON data.


Methods

CreateJsonFile(string Filename, string FileLocation, JObject defaultData)

Creates a new .json file containing the provided default data.

  • Parameters:
    • Filename: Name of the file (without “.json”).
    • FileLocation: Directory in which to create the file.
    • defaultData: The JObject to write as the file’s initial contents.
  • Returns: Task
  • Exceptions:
    • Exception if the directory doesn’t exist or a file with the same name already exists.
    • Wraps any write errors in a generic Exception with an explanatory message.

LoadJsonFile(string Filename, string FileLocation)

Loads and parses an existing .json file into a PariahJSON struct.

  • Parameters:
    • Filename: Name of the file (without “.json”).
    • FileLocation: Directory where the file resides.
  • Returns: Task< PariahJSON > containing the file’s name, path, and parsed JObject.
  • Exceptions:
    • Exception if the directory or file doesn’t exist, or on read/parse errors.

AddToJson(PariahJSON JsonData, string dataName, object data, SecureData? Key)

Encrypts and adds a new data field to the in-memory JSON.

  • Parameters:
    • JsonData: Existing PariahJSON instance.
    • dataName: JSON property name to add.
    • data: The object to serialize & encrypt.
    • Key: Optional SecureData key for encryption; defaults to "skibidi" if null.
  • Returns: Task< PariahJSON > with the updated JSON (does not write to disk).

DeletefromJson(PariahJSON JsonData, string dataName)

Removes a property from the in-memory JSON.

  • Parameters:
    • JsonData: Existing PariahJSON instance.
    • dataName: JSON property name to remove.
  • Returns: PariahJSON with the property removed (does not write to disk).

UpdateJson(PariahJSON JsonData, string dataName, object data, SecureData? Key)

Replaces an existing JSON property with new encrypted data.

  • Parameters:
    • JsonData: Existing PariahJSON instance.
    • dataName: JSON property name to update.
    • data: The new object to serialize & encrypt.
    • Key: Optional SecureData key for encryption; defaults to "skibidi" if null.
  • Returns: Task< PariahJSON > with the updated JSON (does not write to disk).

GetVariable(PariahJSON JsonData, string dataName, SecureData? Key)

Retrieves and decrypts a previously added JSON property.

  • Parameters:
    • JsonData: Existing PariahJSON instance.
    • dataName: JSON property name to retrieve.
    • Key: Optional SecureData key for decryption; defaults to "skibidi" if null.
  • Returns: Task< object > — The decrypted object.
  • Exceptions:
    • Exception if the property is missing or not a string, or on decryption errors.

CheckIfVariableExists(PariahJSON JsonData, string dataName)

Checks whether a given property exists and is a string.

  • Parameters:
    • JsonData: Existing PariahJSON instance.
    • dataName: JSON property name to check.
  • Returns: Task< bool >

SaveJson(PariahJSON JsonData)

Serializes and writes the in-memory JSON back to its original file location.

  • Parameters:
    • JsonData: The PariahJSON holding the file name, path, and updated data.
  • Returns: Task
  • Exceptions:
    • Exception if the directory or file doesn’t exist or on write errors.